import { Alert, Breadcrumb, Button, Card, Modal, Popover, Space, Tabs, Typography } from "antd";
import Search from "@/components/Search";
import Sheet from "@/components/Sheet";
import dayjs from "dayjs";
import { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom";
// import UploadCom from "@/components/UploadCom";
import BtnTool from "@/components/BtnTool";
import { useDispatch } from "react-redux";
import { setShowBtnTool } from "@/store/modules/style";
import Person from "@/components/Person";
import State from "@/components/State";
import { SettingOutlined } from "@ant-design/icons";
import Setable from "@/components/Setable";
import WordShow from "@/components/WordShow";
import { judicialriskAPI } from '@/apis'

const sffxTabs = [
    {
        key: 'sffx_sfxz',
        label: '司法协助',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '被执行人',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '股权数额',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '执行通知文号',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '典型状态',
                dataIndex: 'C5',
                key: 'C5'
            }
        ]
    },
    {
        key: 'sffx_ktgg',
        label: '开庭公告',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '开庭日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '案由',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '案号',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '原告/上诉人',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '被告/被上诉人',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '法庭',
                dataIndex: 'C7',
                key: 'C7'
            }
        ]
    },
    {
        key: 'sffx_qsgg',
        label: '欠税公告',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '发布时间',
                dataIndex: 'C1',
                key: 'C1'
            },
            {
                title: '纳税人识别号',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '欠税税种',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '欠税余额',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '负责人姓名',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '当前新发生欠税',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '税务机关',
                dataIndex: 'C7',
                key: 'C7'
            }
        ]
    },
    {
        key: 'sffx_flss',
        label: '法律诉讼',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '案号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '类型号',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '案件名称',
                dataIndex: 'C5',
                key: 'C5'
            }
        ]
    },
    {
        key: 'sffx_fygg',
        label: '法院公告',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '公告日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '上诉方',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '被诉方',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '公告类型',
                dataIndex: 'C5',
                key: 'C5'
            }
        ]
    },
    {
        key: 'sffx_hbcf',
        label: '环保处罚',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '处罚日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '决定文书号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '处罚事由',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '处罚结果',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '处罚单位',
                dataIndex: 'C6',
                key: 'C6'
            }
        ]
    },
    {
        key: 'sffx_laxx',
        label: '立案信息',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '立案日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '案号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '案件身份',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '法院',
                dataIndex: 'C5',
                key: 'C5'
            }
        ]
    },
    {
        key: 'sffx_zbaj',
        label: '终本案件',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '立案日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '案号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '执行标的',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '未履行金额',
                dataIndex: 'C5',
                key: 'C5',
                render: (dom, rowData, index) => {
                    return rowData.C5?rowData.C5.toLocaleString():rowData.C5
                }
            },
            {
                title: '执行法院',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '终本日期',
                dataIndex: 'C7',
                key: 'C7'
            }
        ]
    },
    {
        key: 'sffx_xzcf',
        label: '行政处罚',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '处罚日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '决定文书号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '处罚事由/违法行为类型',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '处罚结果/内容',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '处罚单位',
                dataIndex: 'C6',
                key: 'C6'
            },
        ]
    },
    {
        key: 'sffx_bzxrxx',
        label: '被执行人信息',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '立案时间期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '执行标的',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '案号份',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '执行法院',
                dataIndex: 'C5',
                key: 'C5'
            }
        ]
    },
    {
        key: 'sffx_sdgg',
        label: '送达公告',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '发布日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '公告名称',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '案号',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '案由',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '案件身份',
                dataIndex: 'C6',
                key: 'C6'
            }
        ]
    },
    {
        key: 'sffx_xzxfl',
        label: '限制消费令',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '立案日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '案号',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '姓名',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '企业信息',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '申请人',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '发布时间',
                dataIndex: 'C7',
                key: 'C7'
            }
        ]
    }
]

export default function Sifafengxian() {

    // 状态参数
    const [activeKey, setActiveKey] = useState('sffx_sfxz');
    const currentTab = useMemo(() => {
        return sffxTabs.find(tab => tab.key === activeKey);
    }, [activeKey]);
    const tabColumns = currentTab?.columns || [];
    const [page, setPage] = useState({ pageNum: 1, pageSize: 10 })
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);
    const dispatch = useDispatch()
    const [sffxSource, setsffxSource] = useState({ total: 0, data: [] })
    useEffect(() => {
        const currentTab = sffxTabs.find(tab => tab.key === activeKey);
        setsffxSource({ total: 0, data: null })
        function getfxdata() {
            judicialriskAPI({
                pagenum: page.pageNum,
                pagesize: page.pageSize,
                risktype: currentTab?.label
            }).then(res => {
                setsffxSource({ total: res.data.total, data: res.data.data })
            })
        }
        getfxdata()
    }, [activeKey,page])
    // 分页
    const handlePage = (pageNum, pageSize) => {
        setPage({
            pageNum,
            pageSize
        })
    }
    // 表格选择
    const handleSelChange = (selectedRowKeys, selectedRows) => {
        setSelectedRowKeys(selectedRowKeys)
        dispatch(setShowBtnTool(selectedRowKeys.length > 0))
    }
    const rowSelection = {
        selectedRowKeys,
        onChange: handleSelChange,
    };
    // 搜索
    const handleSearch = (val) => {
        console.log(val)
    }
    return (
        <div>
            <Tabs type="card" activeKey={activeKey} items={sffxTabs} onChange={(key) => setActiveKey(key)}  />
            <Space direction="vertical" size={16} style={{ width: "100%" }}>
                <Search onSearch={handleSearch}></Search>
                <Card className="table-container">
                    <div className="tableHeader">
                        <h3>明细表</h3>
                    </div>
                    <Sheet columns={tabColumns} dataSource={sffxSource} rowKey='key' page={page} onChange={handlePage}></Sheet>
                </Card>
            </Space>
        </div>
    )
}